package sokoban;
import java.awt.event.KeyEvent;
public class Keypress  {
	private Map m;
	public Keypress(Map m){
		this.m=m;
	}			
	public void checkInput(KeyEvent e){
		int keyCode=e.getKeyCode();
		Dir qq = null;
		boolean dirKey=true;
		if(m.getCanMove()){
			switch(keyCode){
				case KeyEvent.VK_UP:
					qq=Dir.UP;
					break;
				case KeyEvent.VK_DOWN:
					qq=Dir.DOWN;
					break;
				case KeyEvent.VK_RIGHT:
					qq=Dir.RIGHT;	
					break;
				case KeyEvent.VK_LEFT:
					qq=Dir.LEFT;
					break;
				default:
					dirKey=false;
			}
			if(dirKey){
				if(m.checkMove(qq)){
					m.doMove(qq, false);
				}
			}
			else{
				checkInput(e.getKeyChar());
			}
		}
		if(m.checkBoard()){
			m.setCanMove(false);
			m.end();
		}
	}
	public void checkInput(char ch){	
		 if(m.getCanMove()){
			switch(ch){
				
				case 'r':
					m.undoMove();
					break;	
				case 'h':
					m.printHs();
			}
			
		}
		else{
			switch(ch){
				case 'y':
					if(!m.getCanMove()){
						new Sokoban();
					}
					break;
				default:
					System.exit(0);
			}
		}
	}



}
